/**
 * Copyright (c) 2020 kedacom
 * OpenATC is licensed under Mulan PSL v2.
 * You can use this software according to the terms and conditions of the Mulan PSL v2.
 * You may obtain a copy of Mulan PSL v2 at:
 * http://license.coscl.org.cn/MulanPSL2
 * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
 * EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
 * MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
 * See the Mulan PSL v2 for more details.
 **/
<template>
  <div class="gis-home">
    <GisMap />
    <HomeSearchPanel @treeNodeClick="treeNodeClick" @handleClickItem="handleClickItem" @changeType="changeType" />
    <Device ref="device" v-if="type === 'devicemanager'" />
    <transition name="slide-fade">
      <div class="duty-panel" v-if="isShowDutyPanel">
        <dutyRoute ref="dutyRoute" :params="params" @onCloseClick="onCloseClick" />
      </div>
    </transition>
  </div>
</template>

<script>
import GisMap from '../../components/GisMap/index'
import HomeSearchPanel from './componnents/homeSearchPanel/index'
import Device from './componnents/device/device'
import dutyRoute from '../GisManager/components/dutyRoute/dutyRoute.vue'
export default {
  name: 'gis-home',
  components: {
    GisMap,
    HomeSearchPanel,
    Device,
    dutyRoute
  },
  data () {
    return {
      params: {
        type: '1',
        row: {}
      },
      isShowDutyPanel: false,
      dutyRouteBizArr: ['groupcontrol', 'specialserviceroute'],
      type: 'devicemanager'
    }
  },
  props: {
  },
  computed: {
  },
  methods: {
    treeNodeClick (data) {
      this.$refs.device.onRowClick(data)
      this.$refs.device.handleLook(data)
      this.$refs.device.onDetailClick(data)
    },
    changeType (type) {
      this.type = type
      this.isShowDutyPanel = false
    },
    handleClickItem (data) {
      console.log('handleClickItem', data)
      this.handleDutyRouteClick(data)
    },
    handleDutyRouteClick (data) {
      if (this.dutyRouteBizArr.includes(this.type)) {
        this.isShowDutyPanel = true
        this.$nextTick(() => {
          const paramType = this.type === 'groupcontrol' ? '1' : '2'
          this.params = {
            type: paramType,
            row: data.data
          }
        })
      }
    },
    onCloseClick () {
      this.isShowDutyPanel = false
    }
  },
  mounted () {
  }
}
</script>

<style lang="scss" rel="stylesheet/scss" scoped>
</style>
